// function columnToNumber(column) {
//   let number = 0;
//   for (let i = 0; i < column.length; i++) {
//     number = number * 26 + column.charCodeAt(i) - 'A'.charCodeAt(0) + 1;
//   }
//   return number;
// }

console.log(columnToNumber('A')); // 输出1
console.log(columnToNumber('Z')); // 输出26
console.log(columnToNumber('BA')); // 输出27

let ref1 = 'A1:BA102'
function convertRefToRowsAndColumns(ref) {
  const range = ref.split(':');
  const startCell = range[0];
  const endCell = range[1];

  const startColumn = startCell.match(/[A-Z]+/)[0];
  const endColumn = endCell.match(/[A-Z]+/)[0];

  const startRow = parseInt(startCell.match(/\d+/)[0]);
  const endRow = parseInt(endCell.match(/\d+/)[0]);

  const numRows = endRow - startRow + 1;
  const numColumns = columnToNumber(endColumn) - columnToNumber(startColumn) + 1;

  return { numRows, numColumns };
}

/**
 * 字母坐标转数字 AA->27 BA->53
 * @param column 
 * @returns 
 */
function columnToNumber(column) {
  let number = 0;
  for (let i = 0; i < column.length; i++) {
    number = number * 26 + column.charCodeAt(i) - 'A'.charCodeAt(0) + 1;
  }
  return number;
}

const ref = 'A1:FA8';
const { numRows, numColumns } = convertRefToRowsAndColumns(ref1);
console.log(`Rows: ${numRows}, Columns: ${numColumns}`);
